#include "ET++.ph"
#ifdef __GNUG__
#pragma implementation
#endif

#include "EditDialog.h"

#include "Class.h"
#include "Dialog.h"
#include "Scroller.h"
#include "VObjectText.h"
#include "VObjectTView.h"
#include "MenuBar.h"
#include "CommandProcessor.h"
#include "Window.h"
#include "Box.h"
#include "System.h"

//---- EditDialog --------------------------------------------------------------

NewMetaImpl(EditDialog,Manager, (TP(textView), TP(tvClipper)));

EditDialog::EditDialog(const char *t) : Manager(t)
{
}
		
EditDialog::~EditDialog()
{
	SafeDelete(textView);
}

CommandProcessor *EditDialog::MakeCmdProcessor()
{
	return new SingleCommandProcessor;
}

VObject *EditDialog::DoMakeContent()
{
	Scroller *scroller= new Scroller(textView, Point(300, 200), cIdNone, eScrollRight);
	tvClipper= scroller->GetClipper();
	tvClipper->SetFlag(eVObjLayoutCntl);
	SetFirstHandler(textView);
	return scroller;
}

MenuBar *EditDialog::DoMakeMenuBar()
{
	MenuBar *mb= Manager::DoMakeMenuBar();
	mb->AddMenu(TextView::MakeMenu(cFONTMENU));
	mb->AddMenu(TextView::MakeMenu(cSTYLEMENU));
	mb->AddMenu(TextView::MakeMenu(cSIZEMENU));
	mb->AddMenu(TextView::MakeMenu(cFORMATMENU));
	return mb;
}

Point EditDialog::GetInitialWindowSize()
{
	return Point(300, 200);
}

void EditDialog::Control(int id, int detail, void *data)
{
	if (detail == cPartExtentChanged && data == (void*) tvClipper) {
		int w= tvClipper->Width();
		if (textView->Width() != w)
			textView->SetWidth(w);
	} else
		Manager::Control(id, detail, data);
}

void EditDialog::ShowEditDialog(Text *text)
{
	textView= new VObjectTextView(this, Rectangle(300,cFit), (VObjectText*) text);
	OpenAt(0, GetInitialWindowPos(), TRUE, TRUE);
}

void EditDialog::ShowEditor(const char *title, Text *t)
{
	EditDialog *ed= new EditDialog(title);
	ed->ShowEditDialog(t);
	gSystem->AddCleanupObject(ed);
}

